// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------

import {
	HTTP_REQUEST_APP_URL,
	TOKEN,
	USERID
} from '@/config/app';
import {
	toLogin,
	checkLogin
} from '../libs/login';
import store from '../store';


/**
 * 发送请求
 */
function baseRequest(url, method, data) {
	let Url = HTTP_REQUEST_APP_URL

	if (url != '/wx/getWechatURLLink' && url != '/activity/page/getUserAntRamain' && url != '/sms/sendSecuritycode' &&
		url != '/sms/checkSecuritycode' &&
		url != '/ali/getPlayAuthMini' &&
		url != '/wx/getConfigParam1') {
		data = Object.assign({}, {
			userId: store.state.app.appUserId,
			token: store.state.app.md5AppToken
		}, data)
	}
	return new Promise((reslove, reject) => {
		uni.request({
			url: Url + url,
			method: method || 'GET',
			data: data || {},
			success: (res) => {
				reslove(res.data, res);
			},
			fail: (msg) => {
				reject('请求失败');
			}
		})
	});
}

const request = {};

['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
	request[method] = (api, data, opt, params) => baseRequest(api, method, data, opt || {}, params)
});



export default request;